/*
 *	@author Kansas, Marek
 *  Code from SundialOutputTest edited for use with SundialFace
**/

import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;


public class SundialFaceTest {

    /*
     * Test a height less than 500
     */
    @Test(expected = Exception.class)
    public void testHeightException() throws Exception {
            double latitude = 45.0;
            double longitude = 45.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 7; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(499, latitude, hourAngles, true);
    }
    
    
    /*
     * Test a latitude less than 10
     */
    @Test(expected = Exception.class)
    public void testLatitudeLessException() throws Exception {
            double latitude = 9.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 7; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, true);
    }
   
   
    /*
     * Test a latitude greater than 80
     */
    @Test(expected = Exception.class)
    public void testLatitudeGreaterException() throws Exception {
            double latitude = 81.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 7; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, true);
    }
   
   
    /*
     * Test a null ArrayList
     */
    @Test(expected = Exception.class)
    public void testArrayListNullException() throws Exception {
            double latitude = 45.0;
            ArrayList<Double> hourAngles = null;
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, true);
    }
   
   
    /*
     * Test an ArrayList with less than 13 angles
     */
    @Test(expected = Exception.class)
    public void testArrayListLessException() throws Exception {
            double latitude = 45.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 6; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, true);
    }
   
   
    /*
     * Test an ArrayList with more than 13 angles
     */
    @Test(expected = Exception.class)
    public void testArrayListGreaterException() throws Exception {
            double latitude = 45.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 8; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, true);
    }
   
   
    /*
     * Test that DST is true
     */
    @Test
    public void testDSTTrue() throws Exception {
            double latitude = 45.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 7; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, true);
            assertTrue(sf.DST);
    }
   
   
    /*
     * Test that DST is false
     */
    @Test
    public void testDSTFalse() throws Exception {
            double latitude = 45.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 7; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, false);
            assertTrue(!sf.DST);
    }
   
   
   
   
    /*
     * Test that hour angle ArrayList has passed to SundialFace correctly
     */
    @Test
    public void testAngles() throws Exception {
            double latitude = 45.0;
            ArrayList<Double> hourAngles = new ArrayList<Double>();
            double hourAngle;
           
            for (int i = -6; i < 7; i++) {
                    hourAngle = Math.atan(Math.sin(Math.toRadians(latitude))*Math.tan(Math.toRadians(15*i)));
                    hourAngle = Math.toDegrees(hourAngle);
                    hourAngles.add(hourAngle);
            }
           
            SundialFace sf = new SundialFace(500, latitude, hourAngles, false);
            assertTrue(hourAngles == sf.hourAngles);
    }    
    
    
}

